package cc.lj.internal.coupons.interfaces.facade;

import cc.lj.internal.core.exception.ServiceException;
import cc.lj.internal.core.model.PageBean;
import cc.lj.internal.core.model.PageParam;
import cc.lj.internal.coupons.application.service.MartCapAppService;
import cc.lj.internal.coupons.domain.martcap.service.IMartCapDomainService;
import cc.lj.internal.coupons.infrastructure.excepion.CoupousExceptionEnum;
import cc.lj.internal.coupons.interfaces.dto.MartCapDTO;
import cc.lj.internal.coupons.interfaces.dto.command.MartCapAddCommand;
import cc.lj.internal.coupons.interfaces.dto.command.MartCapUpdateCommand;
import cc.lj.internal.coupons.interfaces.dto.convert.MartCapDTOConvertDO;
import cc.lj.internal.coupons.interfaces.dto.query.MartCapListQuery;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.annotation.Resources;
import javax.validation.Valid;
import javax.validation.constraints.DecimalMin;
import java.util.List;

@RestController
@Slf4j
@Validated
@RequestMapping("/martCap")
@Api(tags = "封顶额活动表接口")
public class MartCapController {

    @Resource(name = "martCapDomainServiceImpl")
    private IMartCapDomainService service;

    @Autowired
    private MartCapAppService martCapAppService;

    @PostMapping("/add")
    @ApiOperation(value = "活动添加接口INSET",notes = "1005001002,1005001004")
    public Integer add(@Valid @RequestBody MartCapAddCommand martCapAddCommand)
    {
        Integer id = service.insert(MartCapDTOConvertDO.INSTANCE.convert(martCapAddCommand));
        return id;
    }

    @GetMapping("/getById")
    @ApiOperation(value = "通过主键查询封顶额活动记录QUERY",notes = "1005001006")
    public MartCapDTO getById(@DecimalMin("1") @RequestParam Integer id)
    {
        return MartCapDTOConvertDO.INSTANCE.convert(service.getById(id));
    }

    @PostMapping("/updateById")
    @ApiOperation(value = "通过主键修改封顶额活动UPDATE",notes = "1005001002,1005001006,1005001008")
    public Integer updateById(@Valid @RequestBody MartCapUpdateCommand martCapUpdateCommand)
    {
        return service.updateById(MartCapDTOConvertDO.INSTANCE.convert(martCapUpdateCommand));
    }

    @PostMapping("/getPage")
    @ApiOperation(value = "封顶额活动列表查询接口",notes = "")
    public PageBean<MartCapDTO> getPage(@RequestBody PageParam pageParam)
    {
        PageBean<MartCapDTO> list = martCapAppService.getList(pageParam);
        return list;
    }

}
